package top.forforever.srb.common.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.forforever.srb.common.result.R;

import java.sql.SQLException;

/**
 * @create: 2023/4/30
 * @Description:
 * @FileName: UnifiedExceptionHandler
 * @自定义内容：
 */
@Component
@RestControllerAdvice
public class UnifiedExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e) {
        System.out.println("通用异常处理");
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public R businessExceptionHandler(BusinessException e) {
        System.out.println("业务异常处理");
        System.out.println("业务异常处理记录");
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }

    @ExceptionHandler(SQLException.class)
    public R sqlExceptionHandler(SQLException e) {
        System.out.println("sql语句异常处理");
        System.out.println("sql语句异常处理记录");
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }

}
